package com.example.test.controller;


import com.example.test.bean.BraendType;
import com.example.test.common.model.PageModel;
import com.example.test.common.model.R;
import com.example.test.service.BraendTypeService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dz
 * @since 2022-04-10
 */
@CrossOrigin
@RestController
@RequestMapping("/braend-type")
public class BraendTypeController {

    @Resource
    private BraendTypeService braendTypeService;

    @ApiOperation(value = "根据keyword分页查询品牌")
    @GetMapping("/searchBraends")
    public R pageList(String keyword, PageModel pageModel) {
        return braendTypeService.getBraendByKeyword(keyword,pageModel);
    }

    @ApiOperation(value = "根据id分页查询品牌")
    @GetMapping("/getBraend")
    public R pageList( Long braendId) {
        return braendTypeService.getBraendById(braendId);
    }

    @ApiOperation(value = "商品信息表分页查询")
    @GetMapping("/getAllBraend")
    public R getAllBraends(PageModel pageModel) {
        return braendTypeService.getAllBraend(pageModel);
    }

    @ApiOperation(value = "添加")
    @PostMapping(value = "/insert")
    public R insert(  String braendName) {
        return braendTypeService.addBraend(braendName);
    }

    @ApiOperation(value = "修改")
    @PostMapping(value = "/update")
    public R update(@Validated(BraendType.class) @ApiParam BraendType braendType) {
        return braendTypeService.updateBraend(braendType);
    }

    @ApiOperation(value = "删除")
    @PostMapping(value = "/delete")
    public R<Boolean> delete(@Validated @ApiParam  Long braendId) {
        return braendTypeService.deleteBraend(braendId);
    }

}

